package collcetion;

import java.util.ArrayList;
import java.util.Iterator;

public class CollectionDemo5 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("b");
        list.add("c");
        list.add("d");

        // 创建迭代器对象遍历集合
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            if("b".equals(it.next())){
                // 指向谁，就删除谁
                it.remove();
            }
        }
        System.out.println(list);
    }
}
